package com.crl.rcdp.sys.dao;

import com.crl.dao.BaseDao;
import com.crl.rcdp.sys.model.SysRoleResource;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/6/22 11:10
 */
@Repository
public class SysRoleResourceDao2 extends BaseDao<SysRoleResource, SysRoleResource> {

    /**
     * 新增角色资源对应
     *
     * @param sysRoleResource
     * @return
     */
    public int add(SysRoleResource sysRoleResource) {
        String sql = "insert into td_sys_role_resource(role_id,resource_id) values(:roleId,:resourceId)";
        return insert(sql, sysRoleResource);
    }

    /**
     * 按照roleId删除所有的角色资源对应
     *
     * @param roleId
     * @return
     */
    public int deleteByRoleId(int roleId) {
        String sql = "delete from td_sys_role_resource where role_id=?";
        return delete(sql, roleId);
    }


    /**
     * 根据roleId获取所有角色资源对应
     *
     * @param roleId
     * @return
     */
    public List<SysRoleResource> listByRoleId(int roleId) {
        String sql = "select role_id,resource_id,(select url from td_sys_resource where id=t.resource_id) path from td_sys_role_resource t where role_id=?";
        return list(sql, roleId);
    }


}
